package com.mmall.common;

import com.google.common.collect.Sets;
import org.apache.commons.lang.enums.Enum;
import org.apache.ibatis.javassist.bytecode.CodeAttribute;

import java.util.Set;

/**
 * Created by DongGang on 2017/7/29.
 */
public class Const {

    public static final String CURRENT_USER = "currentUser";

    public interface  Role{
        int ROLE_CUSTOMER = 0;//普通用户
        int ROLE_ADMIN = 1;//管理员
    }

    public static final String EMAIL = "email";
    public static final String USERNAME = "username";

    public interface  productListOrderBy{
        //set时间复杂度是o1 List时间复杂度是on
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_desc","price_asc");//按价格排序

    }

    public interface  Cart{
        int CHECKED = 1;//购物车选中状态
        int UN_CHECKED = 0;//未选中

        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
    }

    public  enum  ProductStatusEnum{
        ON_SALE(1, "在线");

        private String value;
        private int code;

        ProductStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }

    public  enum OrderStatusEnum{
        CANCELED("已取消", 0),
        NO_PAY("未支付", 10),
        PAID("已付款", 20),
        SHIPPED("已发货", 40),
        ORDER_SUCCESS("订单完成", 50),
        ORDER_CLOSE("订单关闭", 60)
        ;

        OrderStatusEnum(String value,int code){
            this.code = code;
            this.value = value;
        }

        private  String value;
        private int code;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public static OrderStatusEnum codeOf(int code) {
            for (OrderStatusEnum orderStatusEnum : values()) {
                if (orderStatusEnum.getCode() == code) {
                    return orderStatusEnum;
                }
            }
            throw new RuntimeException("没有找到相应的枚举");
        }
    }


    public interface  AlipayCallback{
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }


    public  enum PayPlateformEnum{
        ALIPAY("支付宝", 0),

        ;

        PayPlateformEnum(String value,int code){
            this.code = code;
            this.value = value;
        }

        private  String value;
        private int code;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }

    public  enum PaymentTypeEnum{
        ONLINE_PAY ("在线支付", 1),

        ;

        PaymentTypeEnum(String value,int code){
            this.code = code;
            this.value = value;
        }

        private  String value;
        private int code;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public static PaymentTypeEnum codeOf(int code) {
            for (PaymentTypeEnum paymentTypeEnum : values()) {
                if (paymentTypeEnum.getCode() == code) {
                    return paymentTypeEnum;
                }
            }
            throw new RuntimeException("没有找到相应的枚举");
        }
    }



}
